/*
    Copyright Nicolas Ronvel 2007
	gulix33xp@yahoo.fr

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

using System;
using System.Drawing;

using SdlDotNet.Graphics;
using Sdl = SdlDotNet.Graphics;
using SdlDotNet.Core;

using BlindShark.GameElements;
using BlindShark.Widgets;

namespace BlindShark.GameStates
{
	public class GS_CountDown : GameState
	{
		Surface _sfFrame;
		
		Label _lblCountdown;
		
		// Elements location
		Rectangle _rctFrame;
		
		int _iCount;
		
		public GS_CountDown()
		{
			_iCount = 3;
			
			// Initializing the label
			_lblCountdown = new Label(_iCount.ToString(), 40, Color.Red, TextAlignment.CenterMiddle);
			
			ClockManager.AddTimeEvent(new TimeEvent(_iCount + 1,1000, new TimeEvent.Call(DecreaseCount)));
		}
		
		public void Draw()
		{
			// Displaying the frame
			ScreenManager.MainScreen.Blit(_sfFrame, _rctFrame.Location);
			
			// Displaying the countdown
			ScreenManager.MainScreen.Blit(_lblCountdown.Surface, _lblCountdown.Location);
		}
		
		
		public void CleanUp()
		{
			Events.Remove();
			_sfFrame = null;
			_lblCountdown.CleanUp();
		}
		
		public void HandleEvents()
		{
			
		}
		
		public void Update()
		{
			
		}
		
		public void Init()
		{
			// Initializing the frame
			_sfFrame = new Surface(SurfaceManager.GetSurface("gfx/cadre_description.png").Size);
			_sfFrame.Blit(SurfaceManager.GetSurface("gfx/cadre_description.png"));
			_rctFrame = new Rectangle(Point.Empty, _sfFrame.Size);
			_rctFrame.X = (ScreenManager.Width - _rctFrame.Width) / 2;
			_rctFrame.Y = (ScreenManager.Height - _rctFrame.Height) / 2;
			
			// Initializing the label
			_lblCountdown.Location = _rctFrame.Location;
			_lblCountdown.Size = _rctFrame.Size;
			_lblCountdown.Init();
		}
		
		public void DecreaseCount()
		{
			_iCount--;
			
			if (_iCount != 0)
				_lblCountdown.Text = _iCount.ToString();
			else
				_lblCountdown.Text = LanguageManager.Get("CNT_Go");
			_lblCountdown.Init();
			
			if (_iCount==-1)
			 	GameStateManager.PopState();
			
		}
	}
}
